package com.xinjie.www.dao.manager;

import com.xinjie.www.dao.BaseDao;
import com.xinjie.www.po.Manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MangerDaoImpl implements ManagerDao {
    //管理员登陆
    @Override
    public Manager getLoginManger(Connection connection, String managerName) throws SQLException {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        Manager manager = null;
        if (connection != null) {
            String sql = "select * from manager where name=? ";
            Object[] params = {managerName};
            rs = BaseDao.excute(connection, pstm, rs, sql, params);

            if (rs.next()) {
                manager = new Manager();
                manager.setManagerId(rs.getInt("manager_id"));
                manager.setPassword(rs.getString("password"));
                manager.setName(rs.getString("name"));
                manager.setSign(rs.getString("sign"));
            }
            boolean b = BaseDao.closeResource(null, pstm, rs);
            if (b) {
                System.out.println("关闭成功");
            }
        }
        return manager;
    }

    //封禁用户
    @Override
    public int doBan(Connection connection, int userId, int tiebaId) throws SQLException {
        PreparedStatement pstm = null;
        Object[] params = {userId,tiebaId};
        String sql= "insert into ban (user_id,tieba_id) values(?,?)";
        int excute = BaseDao.excute(connection, pstm, sql, params);
        BaseDao.closeResource(null,pstm,null);
        return excute;
    }
}
